using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class ContainerInfo : InteractiveInfo
{
	[Header("Container")]
	public List<InteractiveInfo> contents = new List<InteractiveInfo>();
	
	public override string[] GetStrings()
	{
		string[] text = new string[2];
		text[0] = "Content 1";
		text[1] = "Content 2";
		return text;
	}
	
	public override InteractiveInfo Clone()
	{
		ContainerInfo info = base.CloneInteractive<ContainerInfo>();
		info.contents = contents;
		
		return info;
	}
	
	#region Editor
	// Return true id it is to be removed
	public override DrawResult DrawEditor()
	{
		DrawResult result = base.DrawEditor();
		if (result != DrawResult.None)
		{
			return result;
		}

		DrawContents(contents);
		
		return DrawResult.None;
	}

	public static void DrawContents(List<InteractiveInfo> _contents)
	{
		GUILayoutOption objectSize = GUILayout.Width(Screen.width * 0.3f - 22f);
		GUILayoutOption removeSize = GUILayout.Width(20f);
		GUI.color = (Color.gray + Color.white) / 2f;
		EditorGUILayout.BeginVertical("box");
		{
			GUI.color = Color.white;
			EditorGUILayout.LabelField("Contents");
			
			EditorGUILayout.BeginVertical();
			{
				for (int i = 0; i < _contents.Count; i += 2)
				{
					EditorGUILayout.BeginHorizontal();
					{
						EditorGUILayout.BeginHorizontal();
						{
							_contents[i] = (UseableInfo)EditorGUILayout.ObjectField(_contents[i], typeof(UseableInfo), true, objectSize);
							if (GUILayout.Button("X", removeSize))
							{
								_contents.RemoveAt(i);
								break;
							}
						}
						EditorGUILayout.EndHorizontal();
						
						if (i + 1 < _contents.Count)
						{
							EditorGUILayout.BeginHorizontal();
							{
								_contents[i + 1] = (UseableInfo)EditorGUILayout.ObjectField(_contents[i + 1], typeof(UseableInfo), true, objectSize);
								if (GUILayout.Button("X", removeSize))
								{
									_contents.RemoveAt(i + 1);
									break;
								}
							}
							EditorGUILayout.EndHorizontal();
						}
					}
					EditorGUILayout.EndHorizontal();
				}
			}
			EditorGUILayout.EndVertical();
			
			if (GUILayout.Button("Add Content", GUILayout.Width(100)))
			{
				_contents.Add(null);
			}
		}
		EditorGUILayout.EndVertical();
	}
	#endregion
}
